package vp.remedies.dr.home.utils;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebClient extends WebViewClient  {
	
	@Override
	public void onPageFinished(WebView view, String url) {
	    super.onPageFinished(view, url);
	    view.clearCache(true);
	}

	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		String urlTemp = url.toLowerCase();
/*		if (url.startsWith("local://"))
			url = Constants.RESOURCE_FILE_PATH
					+ url.substring(url.lastIndexOf('/') + 1);
*/		// [TODO:] remove hard coding for file types
		if (urlTemp != null
				&& (urlTemp.endsWith(".avi") || urlTemp.endsWith(".mp4")
						|| urlTemp.endsWith(".mpg") || urlTemp
						.endsWith(".mpeg4")) || urlTemp.endsWith(".3gp")
				|| urlTemp.endsWith(".mov") || urlTemp.endsWith(".flv")) {
			Intent intent = new Intent("android.intent.action.VIEW",
					Uri.parse(url));
			intent.setDataAndType(Uri.parse(url), "video/*");
			view.getContext().startActivity(intent);
			return true;
		} else {
			view.loadUrl(url);
		}
		return true;
	}
}
